/*
 * File: c_main.c
 *
 * Code generated for Simulink model 'c_main'.
 *
 * Model version                  : 1.15
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Sat Sep  4 09:20:47 2021
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "c_main.h"
#include "c_main_private.h"

/* Named constants for Chart: '<Root>/Chart' */
#define c_main_IN_A                    ((uint8_T)1U)
#define c_main_IN_B                    ((uint8_T)2U)
#define c_main_IN_C                    ((uint8_T)3U)
#define c_main_IN_E                    ((uint8_T)1U)
#define c_main_IN_F                    ((uint8_T)2U)
#define c_main_IN_G                    ((uint8_T)3U)
#define c_main_IN_H                    ((uint8_T)4U)

/* Block signals (default storage) */
B_c_main_T c_main_B;

/* Block states (default storage) */
DW_c_main_T c_main_DW;

/* External outputs (root outports fed by signals with default storage) */
ExtY_c_main_T c_main_Y;

/* Real-time model */
static RT_MODEL_c_main_T c_main_M_;
RT_MODEL_c_main_T *const c_main_M = &c_main_M_;

/* Model step function */
void c_main_step(void)
{
  real_T abc;

  /* Sin: '<Root>/Sine Wave' */
  abc = sin(c_main_M->Timing.t[0]) * 5.0;

  /* Chart: '<Root>/Chart' */
  if (c_main_DW.is_active_c3_c_main == 0U) {
    c_main_DW.is_active_c3_c_main = 1U;
    c_main_DW.is_c3_c_main = c_main_IN_A;
  } else {
    switch (c_main_DW.is_c3_c_main) {
     case c_main_IN_A:
     case c_main_IN_C:
      break;

     case c_main_IN_B:
      c_main_DW.is_c3_c_main = c_main_IN_A;
      break;

     default:
      /* case IN_D: */
      switch (c_main_DW.is_D) {
       case c_main_IN_E:
        c_main_B.data1 = 1.0;
        if (abc > 2.0) {
          c_main_DW.is_D = c_main_IN_F;
          c_main_B.data1 = 3.0;
        }
        break;

       case c_main_IN_F:
        c_main_B.data1 = 3.0;
        if (abc > 3.0) {
          c_main_DW.is_D = c_main_IN_G;
        } else if (abc < 1.5) {
          c_main_DW.is_D = c_main_IN_E;
          c_main_B.data1 = 1.0;
        }
        break;

       case c_main_IN_G:
        if (abc > 4.0) {
          c_main_DW.is_D = c_main_IN_H;
        } else if (abc < 2.5) {
          c_main_DW.is_D = c_main_IN_F;
          c_main_B.data1 = 3.0;
        }
        break;

       default:
        /* case IN_H: */
        if (abc < 3.5) {
          c_main_DW.is_D = c_main_IN_G;
        }
        break;
      }
      break;
    }
  }

  /* End of Chart: '<Root>/Chart' */

  /* Outport: '<Root>/data1' incorporates:
   *  Gain: '<Root>/Gain'
   */
  c_main_Y.data1 = 4.0 * c_main_B.data1;

  /* Update absolute time for base rate */
  /* The "clockTick0" counts the number of times the code of this task has
   * been executed. The absolute time is the multiplication of "clockTick0"
   * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
   * overflow during the application lifespan selected.
   */
  c_main_M->Timing.t[0] =
    ((time_T)(++c_main_M->Timing.clockTick0)) * c_main_M->Timing.stepSize0;

  {
    /* Update absolute timer for sample time: [0.01s, 0.0s] */
    /* The "clockTick1" counts the number of times the code of this task has
     * been executed. The resolution of this integer timer is 0.01, which is the step size
     * of the task. Size of "clockTick1" ensures timer will not overflow during the
     * application lifespan selected.
     */
    c_main_M->Timing.clockTick1++;
  }
}

/* Model initialize function */
void c_main_initialize(void)
{
  /* Registration code */
  {
    /* Setup solver object */
    rtsiSetSimTimeStepPtr(&c_main_M->solverInfo, &c_main_M->Timing.simTimeStep);
    rtsiSetTPtr(&c_main_M->solverInfo, &rtmGetTPtr(c_main_M));
    rtsiSetStepSizePtr(&c_main_M->solverInfo, &c_main_M->Timing.stepSize0);
    rtsiSetErrorStatusPtr(&c_main_M->solverInfo, (&rtmGetErrorStatus(c_main_M)));
    rtsiSetRTModelPtr(&c_main_M->solverInfo, c_main_M);
  }

  rtsiSetSimTimeStep(&c_main_M->solverInfo, MAJOR_TIME_STEP);
  rtsiSetSolverName(&c_main_M->solverInfo,"FixedStepDiscrete");
  rtmSetTPtr(c_main_M, &c_main_M->Timing.tArray[0]);
  c_main_M->Timing.stepSize0 = 0.01;
}

/* Model terminate function */
void c_main_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
